<script setup>
import { Plus } from "@element-plus/icons-vue";
import useTable from "@/utils/useTable";
import {http} from "@/api";
import {ref} from "vue";
const categoryList = ref([])
http.DigitizationCategory.list().then(res => {
  categoryList.value = res.data
})
// 行业列表 1数据管理,2分析服务,3通用服务,4安全服务,5可视化工具,6IOT平台
const industryList = ref([
  {
    name: '数据管理',
    id: 1
  },
  {
    name: '分析服务',
    id: 2
  },
  {
    name: '通用服务',
    id: 3
  },
  {
    name: '安全服务',
    id: 4
  },
  {
    name: '可视化工具',
    id: 5
  },
  {
    name: 'IOT平台',
    id: 6
  }
])
/**
 * 表格
 * @type {Ref<UnwrapRef<*[]>>}
 */
const {
  searchParams,
  pageNo,
  pageSize,
  total,
  changePage,
  changeSize,
  dataSource,
  search,
  reset,
  openAdd,
  openView,
  openEdit,
  openDelete
} = useTable({
  requestFn: http.DigitizationApp,
  routerPre: 'DigitizationApp',
  params: {
    name: '',
    categoryId: '',
  }
})
</script>

<template>
  <PageMain title="数智应用管理">
    <el-form label-suffix="：" inline>
      <el-form-item label="名称">
        <el-input clearable v-model="searchParams.name"></el-input>
      </el-form-item>
      <el-form-item label="分类">
        <el-select v-model="searchParams.categoryId">
          <el-option v-for="item in categoryList" :label="item.name" :value="item.id" :key="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="add-box">
      <el-button type="primary" :icon="Plus" @click="openAdd">添加</el-button>
    </div>
    <div class="table-box">
      <el-table :data="dataSource">
        <el-table-column label="名称" prop="name"></el-table-column>
        <el-table-column  label="LOGO" >
          <template #default="scope">
            <ViewImage type="image" :image-url="scope.row.imageUrl"/>
          </template>
        </el-table-column>
        <el-table-column label="版本号" prop="versions"/>
        <el-table-column label="所属行业" prop="industry">
          <template #default="scope">
            <span>{{ industryList.find(item => item.id === scope.row.industry)?.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建者" prop="creator"/>
        <el-table-column label="发布日期" property="time"/>
        <el-table-column label="创建时间" width="180px" prop="createTime"/>
        <el-table-column label="操作" fixed="right">
          <template #default="scope">
            <el-button type="text" @click="openView(scope.row)">查看</el-button>
            <el-button type="text" @click="openEdit(scope.row)">编辑</el-button>
            <el-button type="text" @click="openDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </PageMain>
</template>

<style scoped lang="scss">

</style>
